// 服务分类数据后期改为从后端获取
const serviceArr = [
  {
    text:"家电维修",
    children:[
      {
        id:1,
        text:"空调"
      },
      {
        id:2,
        text:"冰箱"
      },
      {
        id:3,
        text:"洗衣机"
      },
      {
        id:4,
        text:"电视"
      },
      {
        id:5,
        text:"热水器"
      },
      {
        id:6,
        text:"油烟机"
      },
      {
        id:7,
        text:"燃气灶"
      },
    ]
  },
  {
    text:"家电清洗",
    children:[
      {
        id:1,
        text:"空调"
      },
      {
        id:2,
        text:"冰箱"
      },
      {
        id:3,
        text:"洗衣机"
      },
      {
        id:4,
        text:"油烟机"
      }
    ]
  },
  {
    text:"数码办公",
    children:[
      {
        id:1,
        text:"打印机"
      },
      {
        id:2,
        text:"电脑"
      }
    ]
  },
  {
    text:"家电安装",
    children:[
      {
        id:1,
        text:"空调"
      },
      {
        id:2,
        text:"冰箱"
      },
      {
        id:3,
        text:"电视"
      }
    ]
  },
]

Page({
  data: {
    items:serviceArr,
    mainActiveIndex: 0,
    activeId: null,
  },

  onClickNav({ detail = {} }) {
    this.setData({
      mainActiveIndex: detail.index || 0,
      activeId:null
    });
  },

  onClickItem({ detail = {} }) {
    const activeId = this.data.activeId === detail.id ? null : detail.id;

    this.setData({ activeId });
  },

  // 立即预约
  submit(){
    let {mainActiveIndex,activeId} = this.data
    let childName
    if(activeId == null){
      wx.showToast({
        icon:"none",
        title: '您还没有选择任何服务',
      })
    }else{

      let {text:fatherName,children:serviceChildren} = serviceArr[mainActiveIndex]
      for(let item of serviceChildren){
        if(item.id == activeId){
          childName = item.text
          break
        }
      }
      // console.log(fatherName,childName)
      wx.navigateTo({
        url: '/pages/menu/repair/add/index?service='+fatherName+" "+childName,
      })
    }
  },

  onLoad(){
    this.setData({
      mainActiveIndex: 0,
      activeId: null,
    })
  }
})